using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Library.CPP.Rules;

namespace OR.Lazarus.Library.CPP.Rules.Lazarus
{
	/// <summary>
	/// Defines a rule to be applied to variables.  This includes field storage as well as parameters and local declaration rules.
	/// </summary>
   public class VariableRuleDetail : EntityBase
   {
		protected System.String mId;
		protected System.String mContext;
		protected System.Boolean mUseNotation;
		protected System.String mFormat;
		protected string mPrefix;
		protected string mSuffix;
		protected string mScope;
		protected string mDescription;

		public VariableRuleDetail()
		{
	
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Id
		{
			get
			{
				return ( mId );
			}
			set
			{
				mId = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.String Context
		{
			get
			{
				return ( mContext );
			}
			set
			{
				mContext = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.Boolean UseNotation
		{
			get
			{
				return ( mUseNotation );
			}
			set
			{
				mUseNotation = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.String Format
		{
			get
			{
				return ( mFormat );
			}
			set
			{
				mFormat = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Prefix
		{
			get
			{
				return ( mPrefix );
			}
			set
			{
				mPrefix = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Suffix
		{
			get
			{
				return ( mSuffix );
			}
			set
			{
				mSuffix = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Scope
		{
			get
			{
				return ( mScope );
			}
			set
			{
				mScope = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mId = DataUtility.GetString( pSource, "id" );
			mContext = DataUtility.GetString( pSource, "context" );
			mUseNotation = DataUtility.GetBool( pSource, "use-notation", false );
			mFormat = DataUtility.GetString( pSource, "format" );
			mPrefix = DataUtility.GetString( pSource, "prefix" );
			mSuffix = DataUtility.GetString( pSource, "suffix" );
			mScope = DataUtility.GetString( pSource, "scope" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lzr:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lzr", "variable-rule", "http://schemas.icitadel.com/Lazarus/CPP/Rules.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mId ) )
			{
				vNewElement.SetAttribute( "id", mId );
			}
					
			if ( !String.IsNullOrEmpty( mContext ) )
			{
				vNewElement.SetAttribute( "context", mContext );
			}
					
			vNewElement.SetAttribute( "use-notation", mUseNotation.ToString() );
			if ( !String.IsNullOrEmpty( mFormat ) )
			{
				vNewElement.SetAttribute( "format", mFormat );
			}
					
			if ( !String.IsNullOrEmpty( mPrefix ) )
			{
				vNewElement.SetAttribute( "prefix", mPrefix );
			}
					
			if ( !String.IsNullOrEmpty( mSuffix ) )
			{
				vNewElement.SetAttribute( "suffix", mSuffix );
			}
					
			if ( !String.IsNullOrEmpty( mScope ) )
			{
				vNewElement.SetAttribute( "scope", mScope );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lzr", "description", "http://schemas.icitadel.com/Lazarus/CPP/Rules.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.VariableRuleDetail v_oReturn = new Derived.VariableRuleDetail();
			
			v_oReturn.Id = mId;
			v_oReturn.Context = mContext;
			v_oReturn.UseNotation = mUseNotation;
			v_oReturn.Format = mFormat;
			v_oReturn.Prefix = mPrefix;
			v_oReturn.Suffix = mSuffix;
			v_oReturn.Scope = mScope;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections
			
			return ( v_oReturn );
		}

		public virtual Derived.VariableRuleDetail CloneTyped()
		{
			return ( ( Derived.VariableRuleDetail )this.Clone() );
		}
   }
}
   